package com.kzj.service.impl;

import com.kzj.domain.Major;
import com.kzj.dao.MajorDao;
import com.kzj.global.re.Result;
import com.kzj.global.utils.IdGeneratorUtil;
import com.kzj.global.utils.MatchesUtil;
import com.kzj.service.MajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kzj
 * @since 2023-12-01
 */
@Service
public class MajorServiceImpl extends ServiceImpl<MajorDao, Major> implements MajorService {

    @Override
    public Result addMajor(Major major) {
        MatchesUtil.objMatches(major);
        major.setId(IdGeneratorUtil.generatorId(Major.class));
        this.save(major);
        return Result.success();
    }

    @Override
    public Result getAllMajor() {
        List<Major> list = this.list();
        return Result.success(list);
    }

    @Override
    public Result getMajorById(String id) {
        Major major = this.getById(id);
        return Result.success(major);
    }

    @Override
    public Result getMajorByAcademyById(String id) {
        List<Major> majors = this.query().eq("academy_id", id).list();
        return Result.success(majors);
    }
}
